package org.lql.algo.codecrush.week009.question.type.IIII;

import org.lql.algo.common.TreeNode;

/**
 * @author: liangqinglong
 * @date: 2025-08-20 17:05
 * @description: 538. 把二叉搜索树转换为累加树 <a href="https://leetcode.cn/problems/convert-bst-to-greater-tree/description/">...</a>
 **/
public class ConvertBST {

	int sum = 0;

	public TreeNode convertBST(TreeNode root) {
		if (root != null) {
			convertBST(root.right);
			sum += root.val;
			root.val = sum;
			convertBST(root.left);
		}
		return root;
	}

	public static void main(String[] args) {
		ConvertBST convertBST = new ConvertBST();
		TreeNode root = new TreeNode(5);
		root.left = new TreeNode(2);
		root.right = new TreeNode(13);
		convertBST.convertBST(root);
		System.out.println(root);
	}
}
